package com.atwork.wuhua.mvp.presenter;

import com.atwork.wuhua.base.BasePresenter;
import com.atwork.wuhua.base.BaseReq;
import com.atwork.wuhua.base.MyApplication;
import com.atwork.wuhua.bean.EditInfoBean;
import com.atwork.wuhua.bean.HomePageBean;
import com.atwork.wuhua.bean.MyWarBean;
import com.atwork.wuhua.mvp.Callback;
import com.atwork.wuhua.mvp.DataModel;
import com.atwork.wuhua.mvp.Token;
import com.atwork.wuhua.mvp.view.IMyWarActivity;
import com.atwork.wuhua.utils.LogUtils;

public class MyWarPresenter extends BasePresenter<IMyWarActivity> {

    public void getData(String type, int page, String state, String sort) {
        showLoading();
        BaseReq req = new BaseReq();
        req.setKey("uuid", MyApplication.UUID);
        req.setKey("state", state);
        req.setKey("sort", sort);
        req.setKey("type", type);
        req.setKey("page", page + "");
        req.setKey("page_size", "10");
        LogUtils.e("我的预约==》" + req.getString());
        DataModel.request(Token.API_RESERVATION)
                .params(req)
                .execute(new Callback<MyWarBean>() {

                    public void onSuccess(String msg, MyWarBean data) {
                        getView().setData(data);
                        hideLoading();
                    }

                    @Override
                    public void onFailure(String msg) {
                        getView().noData();
                        showToast(msg);
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    /**
     * 取消预约  or  取消约战
     *
     * @param reservation_id
     */
    public void putCancel(String reservation_id) {
        BaseReq req = new BaseReq();
        req.setKey("reservation_id", reservation_id);
        LogUtils.e("reservation_id==>" + reservation_id);
        showLoading();
        if (isViewAttached() && req != null) {
            DataModel.request(Token.API_SITE_CANCEL)
                    .params(req, false)
                    .execute(new Callback<String>() {
                        @Override
                        public void onSuccess(String msg, String data) {
                            showToast(msg);
                            hideLoading();
                            getView().cancelResult();
                        }

                        @Override
                        public void onFailure(String msg) {
                            hideLoading();
                            showToast(msg);
                        }

                        @Override
                        public void onError() {

                        }

                        @Override
                        public void onComplete() {

                        }
                    });
        }
    }
}
